//
//  ShoperDetailViewController.m
//  EasyToTesco
//
//  Created by mc on 16/2/22.
//  Copyright © 2016年 Jack. All rights reserved.
//   商品详情页面

#import "ShoperDetailViewController.h"
#import "HeaderFileForEasyToTesco.h"
#import "ShoperDetailOneTableViewCell.h"
#import "ShoperDetailTwoTableViewCell.h"
//订单详情
#import "OrderDetailViewController.h"
//商品简介
#import "GoodsIntroViewController.h"
//lunbo
#import "SDCycleScrollView.h"
#import "AFNetworking.h"
#import "UIImageView+WebCache.h"
#import "CWStarRateView.h"

//确认订单
#import "ConfirmViewController.h"
#import "ShopCartViewController.h"
#import "StandardsView.h"
#import "ReadLoginData.h"
#import "SVProgressHUD.h"
#import "ShopCartViewController.h"

//富文本
//#import "RCLabel.h"
//#import "RCViewCell.h"

#   define DLog(fmt, ...) NSLog((@"%s [Line %d] " fmt), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__);

#ifndef DLog
#define DLog(fmt,...) NSLog((@"%s [Line %d] " fmt),__PRETTY_FUNCTION__,__LINE__,##__VA_ARGS__)
#endif

@interface ShoperDetailViewController ()<UITableViewDelegate, UITableViewDataSource, SDCycleScrollViewDelegate, StandardsViewDelegate,UIAlertViewDelegate>
{
    //判断是否显示全部评价
    BOOL judgeCell;
    NSString *EvaluationNum;
    UIView *ggView;
    
}
@property (nonatomic, strong)NSMutableDictionary *ShoperDetailDic;

@property (nonatomic, strong)UITableView *shopdetailtableview;
//存放图片的数组
@property (nonatomic, strong)NSMutableArray *picArray;

@property (nonatomic, strong) NSString *color;
@property (nonatomic, strong) NSString *size;
@property (nonatomic, strong) NSString *oneRate;
@property (nonatomic, strong) NSString *count;

@end

@implementation ShoperDetailViewController

- (void)loadView {
    [super loadView];
    [SVProgressHUD show];
}



- (void)viewDidAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    [SVProgressHUD dismiss];
}


- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    
    self.view.contentMode = UIViewContentModeCenter;
    
    [self ShoperDetailInitSomething];

    [self shoperdetailUI];
    
    [self ShoperDetailtableviewUI];
    
    [self addshopDetaildatasources];
    [self getGoodsvaluedatasources];
    
    
}

- (void)ShoperDetailInitSomething {
    judgeCell = YES;
    EvaluationNum = @"156";
    self.picArray = [@[]mutableCopy];
    self.ShoperDetailDic = [[NSMutableDictionary alloc] initWithCapacity:0];
}

- (void)ShoperDetailtableviewUI{
    self.shopdetailtableview = [[UITableView alloc] initWithFrame:CGRectMake(0, HIGHT*0.1, WEITH, HIGHT*0.8+20) style:UITableViewStylePlain];
    self.shopdetailtableview.dataSource = self;
    self.shopdetailtableview.delegate = self;
    [self.view addSubview:self.shopdetailtableview];
}

- (void)shoperdetailUI {
   [self addShoperdetailtopView];
    
    
  [self addlastView];
}


- (void) addlastView {
    UIView *lastView = [[UIView alloc] initWithFrame:CGRectMake(0, HIGHT*0.9+20, WEITH, HIGHT*0.1-20)];
    [self.view addSubview:lastView];
    lastView.userInteractionEnabled = YES;
//    NSArray *array= @[@"加入购物车", @"立即购买"];
    
//    for (NSInteger i=0; i<2; i++) {
        UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
        button.frame = CGRectMake(0, 0, WEITH, HIGHT*0.1-20);
        button.titleLabel.font = [UIFont systemFontOfSize:14];
        button.titleLabel.textAlignment = NSTextAlignmentCenter;
        [button setTitle:@"加入购物车" forState:UIControlStateNormal];
        [button addTarget:self action:@selector(lastBtnClick:) forControlEvents:UIControlEventTouchUpInside];
        button.tag = 330 ;
//        if (i == 1) {
            button.backgroundColor = [UIColor colorWithRed:52/255. green:147/255. blue:225/255. alpha:1];
            [button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
//        }else {
//            button.backgroundColor = [UIColor colorWithRed:244/255. green:244/255. blue:244/255. alpha:1];
//            [button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
//        }
//        
    
        [lastView addSubview:button];
//    }
}

- (float)floatValue
{
    
    return 0.0;
    
}

- (int)intValue
{
    
    return 0;
    
}

- (void)lastBtnClick:(UIButton *)button {
    if (button.tag == 330) {
        
        if (self.color == nil || self.size == nil) {
            [self chooseGuiGe];
            return;
        }
        [self insertShopCart];
        
    } else{
        if (self.color == nil || self.size == nil) {
            [self chooseGuiGe];
            return;
        }
        [self insertShopCart];
        [[NSNotificationCenter defaultCenter] postNotificationName:@"gotoShopCartVC" object:nil];
        ConfirmViewController *confirmVC = [[ConfirmViewController alloc] init];
        confirmVC.count = self.count.intValue;
        confirmVC.goodsInfoArrM = [NSMutableArray array];
        [confirmVC.goodsInfoArrM addObject:self.ShoperDetailDic];
        
        int feilv = [self.oneRate intValue];
        int nums = [self.count intValue];
        int jiage = [self.ShoperDetailDic[@"huiyuanjia"] intValue];
        float oneFeilv = jiage * nums * feilv * 0.01 * 1.0;
        
        confirmVC.picNameNum = 1;
        confirmVC.num = nums;
        
        confirmVC.allRate = confirmVC.allRate + oneFeilv;
        
        confirmVC.allYunFei = confirmVC.allYunFei + [self.ShoperDetailDic[@"jzh"] intValue];
        
        confirmVC.allPrice = jiage * nums;
        
        [self insertShopCart];
        
        [self presentViewController:confirmVC animated:YES completion:nil];
        
    }
}

- (void)insertShopCart {
    
    AFHTTPSessionManager *mgr = [AFHTTPSessionManager manager];
    mgr.responseSerializer = [AFHTTPResponseSerializer serializer];
    
    NSDictionary *dic = [ReadLoginData readLoginData];

    NSString *userName = [dic[@"data"] objectForKey:@"username"];
    NSString *goods_id = self.shopID;
    NSString *price = self.ShoperDetailDic[@"huiyuanjia"];
    NSString *yanse = self.color;
    NSString *chima = self.size;
    NSString *xinghao = self.ShoperDetailDic[@"xinghao"];
    NSString *taocan = self.ShoperDetailDic[@"taocan"];
    NSString *guige = self.ShoperDetailDic[@"guige"];
#warning -------费率问题
#warning -----------用户名固定死数据
#warning ----未登录判断没有加
    if (self.oneRate == nil) {
        self.oneRate = @"0";
    }
    NSString *pid = [NSString stringWithFormat:@"%@",goods_id];
    
    NSDictionary *param = @{@"pid":pid,
                            @"yanse":yanse,
                            @"price":price,
                            @"yanse":yanse,
                            @"chima":chima,
                            @"xinghao":xinghao,
                            @"taocan":taocan,
                            @"guige":guige,
                            @"nums":self.count,
                            @"feilv":self.oneRate,
                            @"username":userName,
                            };
    
    NSString *string = [NSString stringWithFormat:@"http://www.ylgw8.com/AppShopOrder/AddGwc?pid=%@&yanse=%@&price=%@&yanse=%@&chima=%@&xinghao=%@&taocan=%@&guige=%@&num=%@&feilv=%@&username=%@",pid,yanse,price,yanse,chima,xinghao,taocan,guige,self.count,self.oneRate,userName];
    
    NSLog(@"%@",string);
    
//    [mgr POST:@"http://www.ylgw8.com/AppShopOrder/AddGwc" parameters:param success:^(AFHTTPRequestOperation *operation, id responseObject) {
//        NSString *string = [self toArrayOrNSDictionary:responseObject            ];
//        NSLog(@"%@", string);
//        
//        [[NSNotificationCenter defaultCenter] postNotificationName:@"refresh" object:nil];
//    } failure:^(AFHTTPRequestOperation *operation,NSError *error) {
//        
//    }];
    
    [mgr POST:@"http://www.ylgw8.com/AppShopOrder/AddGwc" parameters:param success:^(NSURLSessionDataTask *task, id responseObject) {
        NSDictionary *string = [self toArrayOrNSDictionary:responseObject];
        NSLog(@"%@", string);
        if ([[string objectForKey:@"status"] isEqualToNumber:@1]) {
            UIAlertView *alview = [[UIAlertView alloc] initWithTitle:@"提示" message:@"加入购物车成功" delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
            alview.tag = 10010;
            [alview show];
        } else {
            UIAlertView *alview = [[UIAlertView alloc] initWithTitle:@"提示" message:@"加入购物车失败" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
            [alview show];
        }
                            
    } failure:^(NSURLSessionDataTask *task, NSError *error) {
        
    }];
}

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
    if (alertView.tag == 10010) {
        [self dismissViewControllerAnimated:YES completion:nil];
    }
}

- (void)addShoperdetailtopView {
    UIImageView *image1 = [[UIImageView alloc] initWithFrame:CGRectMake(10, (self.secondView.frame.size.height-20)/2, 20, 20)];
    image1.image = [UIImage imageNamed:@"goback-icon.png"];
    [self.secondView addSubview:image1];
    self.leftBtn.hidden = YES;
    
    UIButton *goBackBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    goBackBtn.frame = CGRectMake(0, 0, self.secondView.frame.size.height, self.secondView.frame.size.height);
    [goBackBtn addTarget:self action:@selector(gobackClick) forControlEvents:UIControlEventTouchUpInside];
    [self.secondView addSubview:goBackBtn];
    self.titleLabel.text = @"商品详情";
    


}

//返回上一级页面
- (void)gobackClick {
    [self dismissViewControllerAnimated:YES completion:nil];
}


#pragma mark -- UITableViewDataSource
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    if (section == 0) {
        return 1;
    }else if (section == 1){
        return 2;
    }else {
        if (judgeCell == YES) {
            return 2;
        } else {
            return 10;
        }
    }
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.section == 0) {
        static NSString *identifier = @"ShoperDetailOneTableViewCell";
        ShoperDetailOneTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
        if (cell == nil) {
            cell = [[[NSBundle mainBundle]loadNibNamed:@"ShoperDetailOneTableViewCell" owner:nil options:nil] lastObject];
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
        }
        
        cell.Titlelabel.text = [NSString stringWithFormat:@"%@", self.ShoperDetailDic[@"title"]];
       cell.pingpailabel.text = [NSString stringWithFormat:@"品牌:%@", self.ShoperDetailDic[@"pinpai"]];
        cell.oldPriceLabel.text = [NSString stringWithFormat:@"库存数量:%@", self.ShoperDetailDic[@"kucun"]];
        cell.PriceNewLabel.text = [NSString stringWithFormat:@"会员价:%@", self.ShoperDetailDic[@"huiyuanjia"]];
        cell.SCpricelabel.text = [NSString stringWithFormat:@"市场价:%@", self.ShoperDetailDic[@"shichangjia"]];
        
        return cell;
        
    } else if (indexPath.section == 1) {

        static NSString *identifier = @"GoodsIntro";
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
        if (cell == nil) {
            cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
        }
        if (indexPath.row == 0) {
            cell.textLabel.text = @"商品简介";

        } else {
            cell.textLabel.text = @"规格选择";
        }
                return cell;
    } else {
        static NSString *identifier = @"ShoperDetailTwoTableViewCell";
        ShoperDetailTwoTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
        if (cell == nil) {
            cell = [[[NSBundle mainBundle]loadNibNamed:@"ShoperDetailTwoTableViewCell" owner:nil options:nil] lastObject];
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
            cell.shoperTwoPic.layer.cornerRadius = CGRectGetHeight(cell.shoperTwoPic.frame)/2;
            cell.shoperTwoPic.layer.masksToBounds = YES;
        }
        return cell;
    }
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 3;
}
#pragma mark -- UITableViewDelegate

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    if (indexPath.section == 0) {
        return 90;
    } else if (indexPath.section == 1) {

                return 30;

      
    } else {
        return 70;
    }
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    if (section == 0) {
        return HIGHT/2 - 10;
    } else if (section == 1){
        return 0.01;
    } else {
        return 30;
    }
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
    if (section == 2) {
        return 0;
    } else {
        return 2.5;
    }
}
- (nullable UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
    UIView *headerView = [[UIView alloc] init];
    headerView.backgroundColor = [UIColor whiteColor];
    if (section == 0) {
        if (self.picArray.count!=0) {
            [self addSdcycleView:headerView];
        }
    } else {
        if (section == 1) {
//            titlabel.text = @"商品简介";
        } else {
            
            UILabel *titlabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 5, 200, 20)];
            titlabel.textAlignment = NSTextAlignmentLeft;
            titlabel.font = [UIFont systemFontOfSize:16];
            titlabel.textColor = [UIColor blackColor];
            [headerView addSubview:titlabel];
            titlabel.text = [NSString stringWithFormat:@"商品评价(%@)", EvaluationNum];
            UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
            button.frame = CGRectMake(CGRectGetMaxX(titlabel.frame)+10, 5, WEITH-CGRectGetMaxX(titlabel.frame)-10, 20);
            [button setTitle:@"加载更多评价" forState:UIControlStateNormal];
            button.titleLabel.font = [UIFont systemFontOfSize:14];
            button.titleLabel.textAlignment = NSTextAlignmentRight;
            [button setTitleColor:[UIColor colorWithRed:52/255. green:147/255. blue:225/255. alpha:1] forState:UIControlStateNormal];
            [button addTarget:self action:@selector(addjudgeBtnClick:) forControlEvents:UIControlEventTouchUpInside];
            [headerView addSubview:button];
            
        }
        
    }
    return headerView;
}

//判断是否加载更多的评价
- (void)addjudgeBtnClick:(UIButton *)button {
    if (judgeCell == YES) {
        [button setTitle:@"收回更多评价" forState:UIControlStateNormal];
    } else {
        [button setTitle:@"加载更多评价" forState:UIControlStateNormal];
    }
    
    judgeCell = !judgeCell;
    [self.shopdetailtableview reloadData];
}

- (nullable UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
    UIView *footView = [[UIView alloc] init];
    footView.backgroundColor = [UIColor grayColor];
    return footView;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
 
    if (indexPath.section == 1) {
        if (indexPath.row == 0) {
            GoodsIntroViewController *goodsIntroVC = [[GoodsIntroViewController alloc] init];
            goodsIntroVC.htmlStr = [NSString stringWithFormat:@"%@", self.ShoperDetailDic[@"about"]];
            [self presentViewController:goodsIntroVC animated:YES completion:nil];
        } else {
//            [self addggViewUI];
            [self chooseGuiGe];
        }
        
    }
}

- (void)chooseGuiGe {
    
    NSLog(@"---------%@", self.ShoperDetailDic);
    NSString *str1 = self.ShoperDetailDic[@"picurl"];
    NSString *str2 = self.ShoperDetailDic[@"picprex"][@"picurl"];
    NSString *str3 = [str2 stringByAppendingString:str1];
    StandardsView *mystandardsView = [self buildStandardView:str3];
    mystandardsView.GoodDetailView = self.view;//设置该属性 对应的view 会缩小
    mystandardsView.showAnimationType = StandsViewShowAnimationShowFrombelow;
    mystandardsView.dismissAnimationType = StandsViewDismissAnimationDisFrombelow;
    [mystandardsView show];
}

-(StandardsView *)buildStandardView:(NSString *)imgUrl {
    
    StandardsView *standview = [[StandardsView alloc] init];
    NSMutableArray *allArrM = [NSMutableArray array];
//    standview.tag = index;
    standview.delegate = self;
    
    [standview.mainImgView sd_setImageWithURL:[NSURL URLWithString:imgUrl]];
    standview.mainImgView.backgroundColor = [UIColor whiteColor];
    standview.priceLab.text = [NSString stringWithFormat:@"%@", self.ShoperDetailDic[@"huiyuanjia"]];
    standview.tipLab.text = @"请选择规格";
    standview.goodNum.text = [NSString stringWithFormat:@"库存 %@件", self.ShoperDetailDic[@"kucun"]];
    
    
    standview.customBtns = @[@"返回",@"确定"];
    int i = 100;
    
    if ([self.ShoperDetailDic[@"yanse"] length] != 0) {
        NSArray *colorArray = [self.ShoperDetailDic[@"yanse"] componentsSeparatedByString:@","];
        NSMutableArray *colorArrM = [NSMutableArray array];
        
        for (NSString *str in colorArray) {
            i ++;
            standardClassInfo *colorClassInfo = [standardClassInfo StandardClassInfoWith:[NSString stringWithFormat:@"%d", i] andStandClassName:str];
            [colorArrM addObject:colorClassInfo];
        }
        
        StandardModel *tempModel = [StandardModel StandardModelWith:colorArrM andStandName:@"颜色"];
        [allArrM addObject:tempModel];
    }
    
    if ([self.ShoperDetailDic[@"chima"] length] != 0) {
        NSArray *sizeArray = [self.ShoperDetailDic[@"chima"] componentsSeparatedByString:@","];
        NSMutableArray *sizeArrM = [NSMutableArray array];
        i = 200;
        for (NSString *str in sizeArray) {
            i ++;
            standardClassInfo *sizeClassInfo = [standardClassInfo StandardClassInfoWith:[NSString stringWithFormat:@"%d", i] andStandClassName:str];
            [sizeArrM addObject:sizeClassInfo];
        }
        
        StandardModel *tempModel2 = [StandardModel StandardModelWith:sizeArrM andStandName:@"尺码"];
        [allArrM addObject:tempModel2];
    }
    
    int num = [self.ShoperDetailDic[@"feilv"] intValue];
    if (num != 0) {
        NSArray *rateArray = [self.ShoperDetailDic[@"feilv"] componentsSeparatedByString:@","];
        NSMutableArray *rateArrM = [NSMutableArray array];
        i = 300;
        for (NSString *str in rateArray) {
            i ++;
            standardClassInfo *rateClassInfo = [standardClassInfo StandardClassInfoWith:[NSString stringWithFormat:@"%d", i] andStandClassName:[NSString stringWithFormat:@"%@",str]];
            [rateArrM addObject:rateClassInfo];
        }
        StandardModel *tempModel3 = [StandardModel StandardModelWith:rateArrM andStandName:@"费率"];
        [allArrM addObject:tempModel3];
    }
    
    standview.standardArr = allArrM;
    
    
    
    return standview;
}

#pragma mark - standardView  delegate
//点击自定义按键
-(void)StandardsView:(StandardsView *)standardView CustomBtnClickAction:(UIButton *)sender
{
    if (sender.tag == 0) {
        //将商品图片抛到指定点
//        [standardView ThrowGoodTo:CGPointMake(200, 100) andDuration:1.6 andHeight:150 andScale:20];
        
        [standardView dismiss];
    }
    else
    {
#warning -------------某些商品无颜色尺码参数
//        NSLog(@"===========%@", self.ShoperDetailDic[@"yanse"]);
//        if ([self.ShoperDetailDic[@"yanse"] length] == 0 && [self.ShoperDetailDic[@"chima"] length] == 0) {
//            self.color = @"无颜色";
//            self.size = @"无尺码";
//            [self insertShopCart];
//            return;
//        }
        NSLog(@"--------%ld", standardView.buyNum);
        self.count = [NSString stringWithFormat:@"%ld", standardView.buyNum];
        NSLog(@"%@-----%@-----%@-----%@", self.color, self.size, self.oneRate, self.count);
        if (self.color == nil) {
            UIAlertView *alview = [[UIAlertView alloc] initWithTitle:@"提示" message:@"请选择颜色" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
            [alview show];
            NSLog(@"请选择颜色");
            return;
        } else if (self.size == nil) {
            UIAlertView *alview = [[UIAlertView alloc] initWithTitle:@"提示" message:@"请选择尺码" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
            [alview show];
            NSLog(@"请选择尺码");
            return;
        } else if ([self.ShoperDetailDic[@"feilv"] intValue] != 0) {
            if (self.oneRate == nil) {
                UIAlertView *alview = [[UIAlertView alloc] initWithTitle:@"提示" message:@"请选择费率" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
                [alview show];
                NSLog(@"请选择费率");
                return;
            }
        }
        
        
        [standardView dismiss];
    }
}

//点击规格代理
-(void)Standards:(StandardsView *)standardView SelectBtnClick:(UIButton *)sender andSelectID:(NSString *)selectID andStandName:(NSString *)standName andIndex:(NSInteger)index
{
    if (sender.selected) {
        switch (index) {
            case 0:
                self.color = sender.titleLabel.text;
                break;
            case 1:
                self.size = sender.titleLabel.text;
                break;
            case 2:
                self.oneRate = sender.titleLabel.text;
            default:
                break;
        }
    } else {
        switch (index) {
            case 0:
                self.color = nil;
                break;
            case 1:
                self.size = nil;
                break;
            case 2:
                self.oneRate = nil;
            default:
                break;
        }
    }
    
    
    NSLog(@"%@---%@---%@", self.color, self.size, self.oneRate);
    NSLog(@"--------%ld", standardView.buyNum);
    DLog(@"selectID = %@ standName = %@ index = %ld",selectID,standName,(long)index);
    
}
//设置自定义btn的属性
-(void)StandardsView:(StandardsView *)standardView SetBtn:(UIButton *)btn
{
    
#warning ---------修改商品规格返回确认按钮颜色！！！
    if (btn.tag == 0) {
        btn.backgroundColor = [UIColor whiteColor];
    }
    else if (btn.tag == 1)
    {
        btn.backgroundColor = [UIColor orangeColor];
    }
}


//- (void)addggViewUI {
//    
//    ggView = [[UIView alloc] initWithFrame:CGRectMake(0, ((HIGHT*0.9)/3)*2, WEITH, (HIGHT)/3)];
//    ggView.backgroundColor = [UIColor greenColor];
//    [self.view addSubview:ggView];
//}

- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
    [self tapclick];
}

- (void)tapclick {
    [ggView removeFromSuperview];
}

- (void)addshopDetaildatasources {
        AFHTTPRequestOperationManager *mgr = [AFHTTPRequestOperationManager manager];
    mgr.responseSerializer = [AFHTTPResponseSerializer serializer];
    
//    NSString *goods_id = self.shopID;
//    NSString *ajax = @"1";
    NSString *url = [NSString stringWithFormat:@"http://ylgw8.com/Product/index/id/%@/ajax/1",self.shopID];

//    NSDictionary *param = @{@"id":[NSString stringWithFormat:@"%@", goods_id], @"ajax":[NSString stringWithFormat:@"%@", ajax]};
    
    [mgr GET:url parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
        NSString *string = [[NSString alloc] initWithData:responseObject encoding:NSUTF8StringEncoding];
        NSDictionary *dic = [self toArrayOrNSDictionary:responseObject];
        self.ShoperDetailDic = dic[@"data"];
     
        
        NSMutableArray *arr = [@[]mutableCopy];
        //        arr = [NSMutableArray arrayWithArray:self.shopIntDic[@"jypic"]];
        
        NSString *imageStr = [NSString stringWithFormat:@"%@", [[[self.ShoperDetailDic[@"picprex"] objectForKey:@"picurl"] componentsSeparatedByString:@" "] firstObject]];
        
        if ([self.ShoperDetailDic[@"picurl"] length]!=0) {
            [arr addObject:[NSString stringWithFormat:@"%@%@", imageStr, self.ShoperDetailDic[@"picurl"]]];
        }
        
        
        NSString *imageStr1 = [NSString stringWithFormat:@"%@", [[[self.ShoperDetailDic[@"picprex"] objectForKey:@"xiaotu"] componentsSeparatedByString:@" "] firstObject]];
        for (NSString *ff in [self.ShoperDetailDic[@"xiaotu"] componentsSeparatedByString:@"||"]) {
            if (ff.length!=0) {
                [arr addObject:[NSString stringWithFormat:@"%@%@", imageStr1, ff]];
            }
        }
        
        self.picArray = [@[]mutableCopy];
        for (NSString *str in arr) {
            [self.picArray addObject:[NSURL URLWithString:[NSString stringWithFormat:@"%@", str]]];
        }
        

        
    
        
        NSLog(@"%@", self.ShoperDetailDic);
        
        [self.shopdetailtableview reloadData];
    } failure:^(AFHTTPRequestOperation *operation,NSError *error)
     {
         //         operation.response.statusCode;//404 401之类
//         NSLog(@"数据请求错误原因:%@", error);
//         NSLog(@"数据请求错误码:%ld", (long)operation.response.statusCode);
     }];
}

- (void)getGoodsvaluedatasources {
    
   AFHTTPRequestOperationManager *mgr = [AFHTTPRequestOperationManager manager];
    mgr.responseSerializer = [AFHTTPResponseSerializer serializer];
    
    NSString *goods_id = self.shopID;
    

    NSDictionary *param = @{@"goods_id":[NSString stringWithFormat:@"%@", goods_id]};
    
    [mgr POST:@"http://www.ylgw8.com/AppGoods/Getcppj" parameters:param success:^(AFHTTPRequestOperation *operation, id responseObject) {
        NSString *string = [[NSString alloc] initWithData:responseObject encoding:NSUTF8StringEncoding];
 
        
        [self.shopdetailtableview reloadData];
    } failure:^(AFHTTPRequestOperation *operation,NSError *error)
     {
         //         operation.response.statusCode;//404 401之类
//         NSLog(@"数据请求错误原因:%@", error);
//         NSLog(@"数据请求错误码:%ld", (long)operation.response.statusCode);
     }];

}

// 将JSON串转化为字典或者数组
- (id)toArrayOrNSDictionary:(NSData *)jsonData{
    NSError *error = nil;
    id jsonObject = [NSJSONSerialization JSONObjectWithData:jsonData
                                                    options:NSJSONReadingAllowFragments
                                                      error:&error];
    
    if (jsonObject != nil && error == nil){
        return jsonObject;
    }else{
        // 解析错误
        return nil;
    }
}

- (void)addSdcycleView:(UIView *)subview {
    //加载本地图片
    //    NSArray *images = @[[UIImage imageNamed:@"L1.jpg"],
    //                        [UIImage imageNamed:@"L2.jpg"],
    //                        [UIImage imageNamed:@"L3.jpg"],
    //                        [UIImage imageNamed:@"L4.jpg"]
    //                        ];
    //加载网络图片
    // 情景二：采用网络图片实现
    NSArray *array = self.picArray;
    
    
    NSArray *imagesURL = [NSArray arrayWithArray:array];//@[
    
    // 情景三：图片配文字
    //    NSArray *titles = @[@"感谢您的支持，如果下载的",
    //                        @"如果代码在使用过程中出现问题",
    //                        @"您可以发邮件到gsdios@126.com",
    //                        @"感谢您的支持"
    //                        ];
    
    CGFloat w = [UIScreen mainScreen].bounds.size.width;
    // 创建不带标题的图片轮播器
    SDCycleScrollView *cycleScrollView = [SDCycleScrollView cycleScrollViewWithFrame:CGRectMake(0, 0, w, HIGHT/2 - 10) imageURLsGroup:imagesURL];
    cycleScrollView.delegate = self;
    [subview addSubview:cycleScrollView];
    // 轮播时间间隔，默认1.0秒，可自定义
    cycleScrollView.autoScrollTimeInterval = 2.5;
    
    
}
//轮播图的代理方法
#pragma mark - SDCycleScrollViewDelegate
- (void)cycleScrollView:(SDCycleScrollView *)cycleScrollView didSelectItemAtIndex:(NSInteger)index{
    
    NSLog(@"---点击了第%ld张图片", index);
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
